package thirt.component
{
	import flash.events.MouseEvent;
	
	import mx.core.UIComponent;
	
	import thirt.event.ColorEvent;

	public class ColorPanle extends UIComponent
	{
		public function ColorPanle()
		{
			super();
			setColorPanle()
		}
		private function setColorPanle():void{
			[Embed (source = "assets/config/colorConfig.txt",mimeType = "application/octet-stream")]
			var colorKey:Class;
			var colorStr:String = new colorKey();
			var ary:Array = colorStr.split("\n");
			var colorAry:Array = new Array;
			for(var i:int;i<ary.length;i++){
				var strAry:Array = String(ary[i]).split("#");
				var obj:Object = new Object;
				obj.name = strAry[0];
				obj.color = parseInt("0x" + strAry[1], 16);
				colorAry.push(obj);
				
				var btn:ColorSprite = new ColorSprite;
				btn.color = parseInt("0x" + strAry[1], 16);
				btn.data = obj;
				this.addChild(btn);
				btn.x = i%9 * 18 + 15;
				btn.y = int(i/9) * 20 + 40;
				btn.addEventListener(MouseEvent.CLICK,onColorSelect);
			}
		}
		private function onColorSelect(event:MouseEvent):void{
			var evt:ColorEvent = new ColorEvent(ColorEvent.COLOREVENT);
			evt.data = ColorSprite(event.target).data;
			this.dispatchEvent(evt);
		}
	}
}